﻿<%@ WebHandler Language="C#" Class="CreateFolder" %>

using System;
using System.Web;
using System.IO;
using System.Collections;
using LitJson;

public class CreateFolder : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string classname = context.Request.Params["classname"].ToString();
        string id = context.Request.Params["id"].ToString();
        string time = context.Request.Params["time"].ToString();
        //文件保存目录路径
        String saveUrl = "/upload/image/";
        String dirPath = context.Server.MapPath(saveUrl);
        if (!Directory.Exists(dirPath))
        {
            showError("上传目录不存在。",context);
        }
        dirPath += classname;
        if (!Directory.Exists(dirPath))
        {
            Directory.CreateDirectory(dirPath);
            DB link = new DB();
            link.Execte("insert into galleryclass value('" + id + "','" + classname + "','" + time + "')");
            showSucess("分类建立成功。",context);
        }
        else { showError("子目录存在。",context);}

    }
    private void showError(string message,HttpContext context)
    {
        Hashtable hash = new Hashtable();
        hash["error"] = 0;
        hash["message"] = message;
        context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
        context.Response.Write(JsonMapper.ToJson(hash));
        context.Response.End();
    }
    private void showSucess(string message,HttpContext context)
    {
        Hashtable hash = new Hashtable();
        hash["error"] = 1;
        hash["message"] = message;
        context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
        context.Response.Write(JsonMapper.ToJson(hash));
        context.Response.End();
    }
    public bool IsReusable {
        get {
            return false;
        }
    }

}